# coding=UTF-8
import datetime
import time


def get_date_time_str():
    return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')


def get_date_str():
    return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d')


def get_format_date_str(format):
    return datetime.datetime.strftime(datetime.datetime.now(), format)


def get_time_str():
    return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d')


def date_to_str(date, format):
    return datetime.datetime.strftime(date, format)


def get_date_time():
    return datetime.datetime.now()


def add_day(date, num):
    return date - datetime.timedelta(days=-num)


def add_hour(date, num):
    return date - datetime.timedelta(hours=-num)


def add_minutes(date, num):
    return date - datetime.timedelta(minutes=-num)


# 字符串转日期
def str_to_date(date_str, format):
    return datetime.datetime.strptime(date_str, format)


def date_str_to_number_tuple(date_str):
    date_list = date_str.split("-")
    year = date_list[0]
    month = date_list[1]
    day = date_list[2]
    return [int(year), int(month), int(day)]


# 计算两个日期相差多少天days
def diff_days(beg_date, end_date):
    start_date_str = parse_date_str(beg_date)
    end_date_str = parse_date_str(end_date)
    start_year_month_day = date_str_to_number_tuple(start_date_str)
    end_year_month_day = date_str_to_number_tuple(end_date_str)
    return (datetime.date(*end_year_month_day) - datetime.date(*start_year_month_day)).days


def parse_date_time_str(date):
    return datetime.datetime.strftime(date, '%Y-%m-%d %H:%M:%S')


def parse_date_str(date):
    return datetime.datetime.strftime(date, '%Y-%m-%d')


def parse_date_str_f(date, format):
    return datetime.datetime.strftime(date, format)


# 获取时间戳 "%Y-%m-%d %H:%M:%S"
def time_to_timestamp(date_str):
    timeArray = time.strptime(date_str, "%Y-%m-%d %H:%M:%S")
    return int(time.mktime(timeArray))


# 时间戳转datetime
def str_to_timeArray(date_str):
    return time.strptime(date_str, "%Y-%m-%d %H:%M:%S")


# 时间戳转日期 "%Y-%m-%d %H:%M:%S"
def timestamp_to_time_str(timeStamp):
    timeArray = time.localtime(timeStamp)
    return time.strftime("%Y-%m-%d %H:%M:%S", timeArray)


# 时间戳转datetime
def timestamp_to_timeArray(timeStamp):
    return time.localtime(timeStamp)


# 获取时间戳
def time_stamp_s():
    return int(round(time.time()))


if __name__ == '__main__':
    print(timestamp_to_time_str(1607563200))
